// 先对二叉树做先序遍历，从底至顶返回最大高度，若判断某子树不是平衡树则剪枝， 直接向上返回

var isBalanced = function (root) {
  const recur = (root) => {
    if (root == null) return 0;
    let left = recur(root.left);
    if (left == -1) return -1;
    let right = recur(root.right);
    if (right == -1) return -1;
    return Math.abs(left - right) < 2 ? Math.max(left, right) + 1 : -1;
  };
  return recur(root) != -1;
};
